package C_Paper;

public class C100_23 {
    public static void main(String[] args) {
        System.out.println(t(new int[]{5000 ,4000 ,3000,2000,1000}));
        System.out.println(t(new int[]{5000, 2000, 5000, 8000, 1800}));
    }
    public static int t(int[] n){
        tree tree = new tree();
        tree.now = n[0];
        for (int i = 1; i < n.length; i++) {
            tree t = new tree();
            t.now = n[i];
            tree.setTree(t);
        }
        return tree.height;
    }
}
class tree{
    public int now;
    public int height = 1;
    public tree left;
    public tree middle;
    public tree right;

    public void setHeight(int i){
        this.height += i;
    }
    public void setTree(tree tree){
        if (this.now - 500 > tree.now) {
            if (this.left == null) {
                this.left = tree;
            } else {
                this.left.setTree(tree);
                setHeight(1);
            }
        }else if (this.now + 500 < tree.now){
            if (this.right == null) {
                this.right = tree;
            } else {
                this.right.setTree(tree);
                setHeight(1);
            }
        }else {
            if (this.middle == null) {
                this.middle = tree;
            } else {
                this.middle.setTree(tree);
                setHeight(1);
            }
        }
    }
}